package com.open.capacity.prints.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.prints.entity.BillGhzp;
import com.open.capacity.prints.service.BillGhzpService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 工行支票
 *
 * @author
 * @email
 * @date 2021-04-07 09:40:46
 */
@RestController
@RequestMapping("ghzps")
@Api(tags = "工行支票")
public class BillGhzpController {

    @Autowired
    private BillGhzpService billGhzpService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_ghzp:billghzp:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billGhzpService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findBySkr")
    @PreAuthorize("hasAnyAuthority('bill_ghzp:billghzp:list')")
    public Result findBySkr(String skr) {
        return Result.succeed(billGhzpService.findBySkr(skr));
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_ghzp:billghzp:list')")
    public Result findById(String id) {
        return Result.succeed(billGhzpService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_ghzp:billghzp:save')")
    public Result save(@RequestBody @Valid BillGhzp billGhzp, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            keyValue = billGhzpService.save(billGhzp);
        } else {
            billGhzp.setId(keyValue);
            keyValue = billGhzpService.update(billGhzp);
        }
        return Result.succeed(keyValue, "操作成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_ghzp:billghzp:delete')")
    public Result delete(@PathVariable String id) {
        billGhzpService.delete(id);
        return Result.succeed("删除成功");
    }

}
